# -*- coding: utf-8 -*-
# @Time    : 2022/2/26 18:20
# @Author  : YanYajun
# 登录
# 假设我们现在在进行某网站的开发，对于某些功能需要登录用户才能调用或者范围
from functools import wraps
def login_check(func):
    @wraps(func)
    def warppss(*wargs,**kwargs):

        if token.startswith("Q"):
            # print("函数名称是：",func.__name__)
            return func(*wargs,**kwargs)
        elif token.startswith('A'):
            if func.__name__!='enter_home_admin':
                return func(*wargs,**kwargs)
        else:
            if func.__name__!='enter_my_page' and func.__name__!='enter_home_admin':
                return func(*wargs,**kwargs)
    return warppss

# def enter_home_admin1(token):
#     print("用户进入管理台页面成功")
#
# def enter_home_page1(token):
#     print("用户进入首页成功")
#
# def enter_my_page1(token):
#     print("用户进入我的页面成功")

@login_check
def enter_home_admin(token):
    print("用户进入管理台页面成功")

@login_check
def enter_home_page(token):
    print("用户进入首页成功")

@login_check
def enter_my_page(token):
    print("用户进入我的页面成功")


def login(name, password):
    """
    root为管理员用户，可以访问所有页面,token是以Q开头
    yanyajun为普通用户，不能访问home_admin页面，token是以A开头
    niming为匿名用户，只能访问home_page页面,token是以Z开头
    用户名和密码输入错误的。token为空，不能访问任何页面token
    :param name:
    :param password:
    :return:
    """
    token = ''
    if name == 'root' and password == "123456":
        token = "Q********"
    elif name == "liaogan" and password == "123456":
        token = "A********"
    elif name == "niming" and password == "123456":
        token = "Z********"
    return token

if __name__ == '__main__':
    token = login('niming', '123456')
    print(token)

    # login_check(enter_home_admin1)(token)
    # login_check(enter_home_page1)(token)
    # login_check(enter_my_page1)(token)
    # login=login_check(enter_home_admin1)
    # login(token)
    """enter_my_page=login_check(enter_my_page)====>enter_my_page(token)  不加装饰器写法"""
    enter_home_admin(token)
    enter_home_page(token)
    enter_my_page(token)
